import { CallHandler, ExecutionContext, Injectable, NestInterceptor, } from '@nestjs/common';
import { map, Observable } from 'rxjs';

@Injectable()
export class TransformInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    return next.handle().pipe(
      map((data) => {
        if (data?.isAdd) {
          return { code: 0, data: "success" };
        }
        return {
          data,
          code: 0,
        }
      }),
    );
  }
}
